package com.nurese.service;

import com.github.pagehelper.PageHelper;
import com.nurese.dao.EvaluateDao;
import com.nurese.dao.EvaluateDao;
import com.nurese.entity.Evaluate;
import com.nurese.entity.Evaluate;
import com.nurese.utils.BeanMapUtils;
import com.nurese.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EvaluateService {
    @Autowired
    private EvaluateDao evaluateDao;

    public int create(Evaluate evaluate){
        return evaluateDao.create(evaluate);
    }
    public int delete(Integer id){
//        Map<String,Object> map=new HashMap<>();
//        map.put("id",id);
//        return evaluateDao.delete(map);

        return evaluateDao.delete(MapParameter.getInstance().add("id",id).getMap());
    }

    public int delete(String ids){

        String[] arr=ids.split(",");
        int flag=0;
        for (String s:arr){
            flag=evaluateDao.delete(MapParameter.getInstance().addId(Integer.parseInt(s)).getMap());
        }
        return flag;
    }
    public int update(Evaluate evaluate){
//        Map<String,Object> map= BeanMapUtils.beanToMapForUpdate(evaluate);
//        return evaluateDao.update(map);

        return evaluateDao.update(MapParameter.getInstance()
                .add(BeanMapUtils.beanToMapForUpdate(evaluate))
                .addId(evaluate.getId()).getMap());
    }
    public List<Evaluate> query(Evaluate evaluate){
        System.out.println("++++1:"+BeanMapUtils.beanToMap(evaluate));
        if (evaluate !=null && evaluate.getPage() !=null){
            PageHelper.startPage(evaluate.getPage(),evaluate.getLimit());
        }
        return evaluateDao.query(BeanMapUtils.beanToMap(evaluate));
    }
    public int count(Evaluate evaluate){
        return evaluateDao.count(BeanMapUtils.beanToMap(evaluate));
    }
    public Evaluate detail(Integer id){
        return evaluateDao.detail(MapParameter.getInstance().add("id",id).getMap());
    }
}